<%= content_tag :nav, class: "navbar navbar-expand-md bg-primary", id: "main-navbar",
      data: {
        bs_theme: "dark"
      }.merge(tour_attributes(id: "main-navbar", title: t("tour.navbar.main.title", name: site_name), description: t("tour.navbar.main.description"))) do %>
  <div class='container-fluid'>
    <a class="navbar-brand ms-2" href="<%= root_path %>" aria-label="<%= translate ".home" %>">
      <%= image_tag site_icon, alt: site_name, height: "40px", class: "me-2" %>
      <span class="d-md-none"><%= site_name %></span>
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="<%= translate ".navbar.toggler.label" %>">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse row" id="navbar">
      <ul class="navbar-nav col ps-4 ps-md-0 align-self-start" role="presentation">
        <li class="nav-item" role="presentation">
          <%= nav_link "box", Model.model_name.human(count: 100), models_path(@filter&.to_params), text_style: "d-md-none d-lg-inline", id: "nav-link-models",
                data: tour_attributes(id: "nav-link-models", title: Model.model_name.human(count: 100), description: t("tour.navbar.models.description")) %>
        </li>
        <li class="nav-item" role="presentation">
          <%= nav_link "people", Creator.model_name.human(count: 100), creators_path(@filter&.to_params(except: :creator)), text_style: "d-md-none d-lg-inline", id: "nav-link-creators",
                data: tour_attributes(id: "nav-link-creators", title: Creator.model_name.human(count: 100), description: t("tour.navbar.creators.description")) %>
        </li>
        <li class="nav-item" role="presentation">
          <%= nav_link "collection", Collection.model_name.human(count: 100), collections_path(@filter&.to_params(except: :collection)), text_style: "d-md-none d-lg-inline", id: "nav-link-collections",
                data: tour_attributes(id: "nav-link-collections", title: Collection.model_name.human(count: 100), description: t("tour.navbar.collections.description")) %>
        </li>
        <% if SiteSettings.show_libraries %>
          <% policy_scope(Library).find_each do |library| %>
            <li class="nav-item" role="presentation">
              <%= nav_link(
                    library.icon.presence || "boxes",
                    library.name,
                    models_path({library: library}.merge(@filter&.to_params(except: :library) || {})),
                    title: library.caption
                  )	%>
            </li>
          <% end %>
        <% end %>
      </ul>
      <ul class="navbar-nav col-auto pe-4 align-self-start justify-content-end" role="presentation">
        <li class="nav-item" role="presentation">
          <% if policy(:upload).index? %>
            <div class="btn-group">
              <%= content_tag :button,
                    type: "button",
                    id: "nav-link-upload",
                    class: "btn btn-warning btn-sm mt-1 me-1 dropdown-toggle",
                    data: {
                      bs_toggle: "dropdown"
                    }.merge(tour_attributes(
                      id: "nav-link-upload",
                      title: t(".add_models"),
                      description: t("tour.navbar.add_models.description")
                    )),
                    aria: {
                      expanded: false,
                      haspopup: "menu",
                      controls: "add-content-menu"
                    } do
                    safe_join [Icon(icon: "plus-circle"), t(".add_models")], " "
                  end %>
              <ul class="dropdown-menu" role="menu" id="add-content-menu">
                <%= DropdownItem label: t(".upload"), path: new_model_path %>
                <%= DropdownItem label: t(".import_url"), path: new_import_path %>
              </ul>
            </div>
          <% end %>
        </li>
        <li class="nav-item" role="presentation">
          <% if policy(:scan).create? %>
            <% if @scan_in_progress %>
              <%= nav_link "", t(".scanning"), activity_path, nofollow: true, style: "btn btn-outline-warning btn-sm me-1 mt-lg-1", icon_style: "spinner-border spinner-border-sm" %>
            <% else %>
              <div class="btn-group">
                <button type="button" data-bs-toggle="dropdown" aria-expanded="false"
                  class="btn btn-warning btn-sm mt-1 me-1 dropdown-toggle">
                  <%= Icon(icon: "radar") %>
                  <%= t ".scan" %>
                </button>
                <ul class="dropdown-menu">
                  <%= DropdownItem label: t(".scan_changes.label"), path: scans_path, method: :post, confirm: translate(".scan_changes.confirm") %>
                  <%= DropdownItem label: t(".check_existing.label"), path: scans_path(type: :check), method: :post, confirm: translate(".check_existing.confirm") %>
                  <%= DropdownItem label: t(".check_results.label"), path: scans_path({type: :check}.merge(@filter.to_params)), method: :post, confirm: translate(".check_results.confirm") if @filter&.any? %>
                </ul>
              </div>
            <% end %>
          <% end %>
        </li>
        <%- if current_user %>
          <% if policy(Problem).index? && Problem.visible(problem_settings).count > 0 %>
            <li class="nav-item" role="presentation">
              <% severity = max_problem_severity(policy_scope(Problem).all) %>
              <%= nav_link problem_icon(severity),
                    Problem.model_name.human(count: 100),
                    problems_path,
                    title: translate("problems.severities.#{severity}"), # rubocop:todo I18n/RailsI18n/DecorateStringFormattingUsingInterpolation
                    icon_style: "link-#{severity}",
                    text_style: "d-md-none",
                    aria_label: Problem.model_name.human(count: 100) %>
            </li>
          <% end %>
          <% if policy(:activity).index? %>
            <li class="nav-item" role="presentation">
              <%= nav_link "activity", t(".activity"), activity_path, nofollow: true, text_style: "d-md-none" %>
            </li>
          <% end %>
          <% if policy(:settings).index? %>
            <li class="nav-item" role="presentation">
              <%= nav_link "gear", t(".settings"), settings_path, nofollow: true, text_style: "d-md-none" %>
            </li>
          <% end %>
          <% if policy(:user).index? and not policy(:settings).index? %>
            <li class="nav-item" role="presentation">
              <%= nav_link "people", t(".moderator_settings"), settings_users_path, nofollow: true, text_style: "d-md-none" %>
            </li>
          <% end %>
        <% end %>
        <%- unless current_page?(root_path) %>
          <li id="nav-search" class="nav-item ms-1 me-3" data-turbo-permanent>
            <%= form_with url: models_path, method: :get, role: "search" do |f| %>
              <%= f.search_field :q, class: "form-control", placeholder: translate(".search"), aria_label: translate(".search"), aria_describedby: "button-search", value: @query || params[:q] %>
            <% end %>
          </li>
        <% end %>
        <%- if current_user %>
          <%- if SiteSettings.multiuser_enabled? %>
            <li class="nav-item dropdown" role="presentation">
              <%= content_tag :button, id: "nav-link-preferences", title: t(".account"), class: "btn btn-light btn-sm mt-1",
                    data: {bs_toggle: "dropdown"}.merge(
                      tour_attributes(id: "nav-link-preferences", title: t(".account"), description: t("tour.navbar.account.description"))
                    ),
                    aria: {
                      expanded: false,
                      haspopup: true,
                      controls: "preferences-menu"
                    } do %>
                <%= Icon(icon: "person") %>
              <% end %>
              <ul class="dropdown-menu dropdown-menu-end" id="preferences-menu">
                <%= DropdownItem label: t("devise.registrations.edit.title"), path: edit_user_registration_path %>
                <%= DropdownDivider() %>
                <%= DropdownHeader text: t(".my_stuff") %>
                <%= DropdownItem label: Model.model_name.human(count: 100), path: models_path(owner: current_user.to_param) %>
                <%= DropdownItem label: Creator.model_name.human(count: 100), path: creators_path(owner: current_user.to_param) %>
                <%= DropdownItem label: Collection.model_name.human(count: 100), path: collections_path(owner: current_user.to_param) %>
                <%- if SiteSettings.federation_enabled? %>
                  <%= DropdownDivider() %>
                  <%= DropdownHeader text: t(".social") %>
                  <%= DropdownItem label: t("follows.index.title"), path: follows_path %>
                <%- end %>
                <%= DropdownDivider() %>
                <%= DropdownItem icon: "box-arrow-right", label: t(".log_out"), path: destroy_user_session_path, method: :delete %>
              </ul>
            </li>
          <% else %>
            <li class="nav-item" role="presentation">
              <%= nav_link "person", t("devise.registrations.edit.title"), edit_user_registration_path, nofollow: true, text_style: "d-md-none", id: "nav-link-preferences",
                    data: tour_attributes(id: "nav-link-preferences", title: t(".account"), description: t("tour.navbar.account.description")) %>
            </li>
          <% end %>
        <% end %>
        <%- if SiteSettings.multiuser_enabled? && current_user.nil? %>
          <li class="nav-item" role="presentation">
            <%= nav_link "box-arrow-in-right", t(".log_in"), new_user_session_path, title: translate(".log_in"), nofollow: true, style: "btn btn-light" %>
          </li>
        <%- end %>
      </ul>
    </div>
  </div>
<% end %>
